home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / GCC 1.37.1r14 / usr / gcc-1.37.1r14 / object oriented files / CResBrowser.cp < prev    next >
Encoding:
Text File  |  1993-08-03  |  6.0 KB  |  224 lines  |  [TEXT/KAHL]

  1. /******************************************************************************
  2.  CResBrowser.c
  3.  
  4.         A subclass of CDirector that manages a window containing a list
  5.         of resources.
  6.         
  7.     SUPERCLASS = CDirector
  8.     
  9.     Copyright © 1991 Symantec Corporation. All rights reserved.
  10.     
  11.     TCL 1.1.3 Changes
  12.     [
  13.         - CResBrowser::MakeResourceWindow must return a CDirector * value, in this
  14.           case, 0.
  15.     ]
  16.  ******************************************************************************/
  17.  
  18. #include "CResBrowser.h"
  19. #include "CResListPane.h"
  20. #include "CBrowseResDoc.h"
  21. #include "TBUtilities.h"
  22. #include "CDesktop.h"
  23. #include "CScrollPane.h"
  24. #include "CDecorator.h"
  25. #include "CWindow.h"
  26. #include "CArray.h"
  27.  
  28. #define    kResBrowseWind    1025        // 'WIND' resource ID 
  29. #define        cmdOpenType            1050    // open window on a resource type
  30. #define        cmdOpenResource        1051    // open window on a resource
  31.  
  32. extern CDesktop     *gDesktop;
  33. extern CDecorator    *gDecorator;
  34.  
  35. /******************************************************************************
  36.  IResBrowser
  37.  
  38.      Initialize CResBrowser. Creates a window to display the given list of
  39.      resources of the given type.
  40.      
  41. ******************************************************************************/
  42.  
  43. void CResBrowser::IResBrowser( CBrowseResDoc *aSupervisor, ResType aResType, 
  44.                         CArray *aResList)
  45. {
  46.     Str255    title;
  47.     Str31    suffix;
  48.     
  49.     resType = aResType;
  50.     itsResList = aResList;
  51.     itsResPane = NULL;
  52.     
  53.     CDirector::IDirector( aSupervisor);
  54.     
  55.         // set the title of the window to Filename - ResType,
  56.         // e.g. "Sample - DLOG"
  57.     
  58.     aSupervisor->GetName( title);
  59.     ConcatPStrings( title, "\p - xxxx");
  60.     BlockMove( &aResType, &title[ Length(title) - 3], sizeof(ResType));
  61.     
  62.         // create the window
  63.         
  64.     BuildWindow();
  65.     
  66.         // Set the window title
  67.         
  68.     itsWindow->SetTitle( title);
  69.     
  70.         // Position the window on screen and show it.
  71.         
  72.     gDecorator->StaggerWindow( itsWindow);
  73.     itsWindow->Select();
  74. }
  75.  
  76. /******************************************************************************
  77.  Dispose
  78.  
  79.      Dispose of the resource list when the window is closed.
  80.      
  81. ******************************************************************************/
  82.  
  83. void CResBrowser::Dispose( void)
  84. {
  85.     ForgetObject( itsResList);
  86.     inherited::Dispose();
  87. }
  88.  
  89. /******************************************************************************
  90.  DoCommand
  91.  
  92.      Respond to the cmdOpenResource command. It is sent when the user
  93.      double clicks on a resource name/ID.
  94.      
  95. ******************************************************************************/
  96.  
  97. void CResBrowser::DoCommand( long aCommand)
  98. {
  99.     tResourceInfo    resInfo;
  100.     Cell            selectedCell;
  101.     
  102.     switch( aCommand)
  103.     {
  104.         case cmdOpenResource:
  105.         
  106.                 // determine the selected cell.
  107.                 
  108.             selectedCell.h = selectedCell.v = 0;
  109.             if (itsResPane->GetSelect( kCurrentOrNext, &selectedCell))
  110.             {
  111.             
  112.                     // get the resource info for the selected cell
  113.                     // if it alreadt has a window, just show it,
  114.                     // otherwise create a new window for the resource
  115.                     
  116.                 itsResList->GetItem( &resInfo, selectedCell.v+1);
  117.                 if (resInfo.window)
  118.                     resInfo.window->GetWindow()->Select();
  119.                 else
  120.                 {
  121.                     
  122.                     resInfo.window = MakeResourceWindow( &resInfo);
  123.                     itsResList->SetItem( &resInfo, selectedCell.v + 1);
  124.                 }
  125.             }
  126.             break;
  127.             
  128.         default:
  129.             inherited::DoCommand( aCommand);
  130.             break;
  131.     }
  132. }
  133.  
  134. /******************************************************************************
  135.  BuildWindow
  136.  
  137.      Creates the window for display the resource list. CResListPane is a
  138.      subclass of CArrayPane that displays the scrolling list of resources.
  139.      
  140. ******************************************************************************/
  141.  
  142. void CResBrowser::BuildWindow( void)
  143. {
  144.     CScrollPane    *scrollPane;
  145.     
  146.         // First, create a window.
  147.     
  148.     itsWindow = new CWindow;
  149.     itsWindow->IWindow( kResBrowseWind, kNotFloating, gDesktop, this);
  150.     
  151.         // Next, add a scroll pane with a vertical scroll bar and
  152.         // a size box.
  153.         
  154.     scrollPane = new CScrollPane;
  155.     scrollPane->IScrollPane( itsWindow, this, 0, 0, 0, 0,
  156.                     sizELASTIC, sizELASTIC, kNoHScroll, kHasVScroll, kHasSizebox);
  157.     scrollPane->FitToEnclFrame( kDoHorizontal, kDoVertical);
  158.     
  159.         // Next, add the CResListPane
  160.  
  161.     itsResPane = new CResListPane;
  162.     itsResPane->IResListPane( scrollPane, this, 0, 0, 0, 0,
  163.                     sizELASTIC, sizELASTIC);
  164.     itsResPane->FitToEnclosure( kDoHorizontal, kDoVertical);
  165.     
  166.         // Install the resource list into the CResListPane,
  167.         // and set the double click command and selection flags
  168.     
  169.     itsResPane->SetArray( itsResList, FALSE);
  170.     itsResPane->SetDblClickCmd( cmdOpenResource);
  171.     itsResPane->SetSelectionFlags( selOnlyOne);
  172.     
  173.         // Connect the panorama to the scroll pane.
  174.  
  175.     scrollPane->InstallPanorama( itsResPane);
  176.     
  177.     itsGopher = itsResPane;
  178. }
  179.  
  180. /******************************************************************************
  181.  MakeResourceWindow
  182.  
  183.      Called when the user double clicks on a resource in the list. Subclasses
  184.      must override to display a particular resource type. CDLOGBrowser
  185.      overrides this method to display a DLOG window. This method just beeps.
  186. ******************************************************************************/
  187.  
  188. CDirector *CResBrowser::MakeResourceWindow( tResourceInfo *aResource)
  189. {
  190.     SysBeep( 3);
  191.     return 0;
  192. }
  193.  
  194. /******************************************************************************
  195.  RemoveDirector {OVERRIDE}
  196.  
  197.      RemoveDirector is called when a subordinate director is being closed.
  198.      Since we store a reference to the subordinate director associated with
  199.      a resource in itsResList, we must be sure to clear that reference when
  200.      the subordinate director is closed.
  201. ******************************************************************************/
  202.  
  203.     static int FindResDirector( CDirector *resDirector, tResourceInfo *resInfo)
  204.     {
  205.         if (resInfo->window == resDirector)
  206.         {
  207.             resInfo->window = NULL;
  208.             return 0;
  209.         }
  210.         return 1;
  211.     }
  212.  
  213. void CResBrowser::RemoveDirector( CDirector *aDirector)
  214. {
  215.         // Search the resource list to find the reference to
  216.         // this director. The search routine clears the
  217.         // reference as soon as it is found.
  218.         
  219.     if (itsResList)
  220.         itsResList->Search( aDirector, (CompareFunc) FindResDirector);
  221.     
  222.     inherited::RemoveDirector( aDirector);
  223. }
  224.